package com.auto.code.service.impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.auto.code.dao.DBInfoDAO;
import com.auto.code.domain.DBInfoDO;
import com.auto.code.domain.DBInfoDTO;
import com.auto.code.service.DBInfoService;
import com.auto.code.util.MapUtils;
import com.auto.code.util.ObjectClone;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class DBInfoServiceImpl implements DBInfoService {
	@Autowired
	private DBInfoDAO dbInfoDAO;

	@Override
	public int deleteById(Long id) {
		return dbInfoDAO.deleteById(id);
	}

	@Override
	public int create(DBInfoDTO record) {
		DBInfoDO entity = new DBInfoDO();
		BeanUtils.copyProperties(record, entity);
		return dbInfoDAO.insert(entity);
	}

	@Override
	public DBInfoDTO getById(Long id) {
		DBInfoDTO dto = new DBInfoDTO();
		BeanUtils.copyProperties(dbInfoDAO.getById(id), dto);
		return dto;
	}

	@Override
	public int update(DBInfoDTO record) {
		DBInfoDO entity = new DBInfoDO();
		BeanUtils.copyProperties(record, entity);
		return dbInfoDAO.update(entity);
	}

	@Override
	public PageInfo<DBInfoDTO> queryPage(DBInfoDTO dBInfoDTO) {
		PageHelper.startPage(dBInfoDTO.getPageNum(), dBInfoDTO.getPageSize());
		List<DBInfoDO> dbInfoDOS = dbInfoDAO.queryList(MapUtils.parseMap(dBInfoDTO));
		List<DBInfoDTO> dbInfoDTOList = ObjectClone.cloneList(dbInfoDOS, DBInfoDTO.class);
		return new PageInfo<>(dbInfoDTOList);
	}

	@Override
	public List<DBInfoDTO> queryList(DBInfoDTO dBInfoDTO) {
		List<DBInfoDO> dbInfoDOS = dbInfoDAO.queryList(MapUtils.parseMap(dBInfoDTO));
		List<DBInfoDTO> dbInfoDTOList = ObjectClone.cloneList(dbInfoDOS, DBInfoDTO.class);
		return dbInfoDTOList;
	}

}
